/**
 * 这是一个Express应用示例
 * Created by ford on 15-6-2.
 */
var express = require('express');
var app = express();

//以下三行命令告诉Express所有视图都放在名为views的目录下，__dirname指代码文件运行的目录
app.set('view engine', 'jade');
app.set('view options', {layout:true});
app.set('views', __dirname + '/views');

app.get('/stooges/:name?', function(req, res, next){
	var name = req.params.name;

	switch (name ? name.toLowerCase() : ''){
		case 'larry':
		case 'curly':
		case 'moe':
			res.send(name + ' is my favorite stooge.');
			break;

		default :
			next();
	}
});

app.get('/stooges/*?', function(req, res){
	res.send('no stooges listed');
});

app.get('/?', function(req, res){
	res.send('hello world');
});

var port = 8080;
app.listen(port);
console.log('listening on port ' + port);